﻿using FortuneUniverse.Fortune.Dyson;

namespace FortuneUniverse.Fortune.Util
{
    public static class DataSerializer
    {
        /// <summary>
        /// out byte
        /// 将光谱和巨星类型整合，如果不是巨星，直接返回type
        /// 如果是巨星，则返回 (光谱+1) * 10，M：11、K：21.。。。X：71
        /// </summary>
        /// <param name="starType"></param>
        /// <param name="spectr"></param>
        /// <returns></returns>
        public static int genStarType(ESpectrType spectr, EStarType starType)
        {
            if (starType == EStarType.GiantStar)
            {
                return ((int) spectr + 1) * 10 + (int) starType;
            }

            return (int) starType;
        }
        
        /// <summary>
        /// 真实数值为当前数值/10.0
        /// </summary>
        /// <param name="currentStar"></param>
        /// <param name="birthStar"></param>
        /// <returns></returns>
        public static int genDistance(StarData currentStar, StarData birthStar)
        {
            return (int) ((currentStar.uPosition - birthStar.uPosition).magnitude * 10 / 2400000.0);
        }
        
        /// <summary>
        /// out short
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public static int mergeByte(byte left, byte right)
        {
            return left << 8 | right;
        }
        
        /// <summary>
        /// 映射矿物key
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public static string mapVeinName(int index)
        {
            switch (index)
            {
                case 1:
                    return "fe";
                case 2:
                    return "cu";
                case 3:
                    return "si";
                case 4:
                    return "ti";
                case 5:
                    return "stone";
                case 6:
                    return "coal";
                case 7:
                    return "oil";
                case 8:
                    return "fireIce";
                case 9:
                    return "diamond";
                case 10:
                    return "fractal";
                case 11:
                    return "crysrub";
                case 12:
                    return "grat";
                case 13:
                    return "bamboo";
                case 14:
                    return "mag";
                default:
                    return "";
            }
        }

        
    }
}